package com.heima.behavior.service.impl;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.behavior.mapper.ApBehaviorEntryMapper;
import com.heima.behavior.service.ApBehaviorEntryService;
import com.heima.model.behavior.pojos.ApBehaviorEntry;
import org.springframework.stereotype.Service;

/**
 * @ClassName ApBehaviorEntryServiceImpl
 * @Description 用户实体服务层
 * @Author AWei
 * @DATE 2021/4/22 21:14
 * @Version 1.0
 */
@Service
public class ApBehaviorEntryServiceImpl extends ServiceImpl<ApBehaviorEntryMapper, ApBehaviorEntry> implements ApBehaviorEntryService {
    @Override
    public ApBehaviorEntry findByUserIdOrEquipmentId(Integer userId, Integer equipmentId) {
        //根据用户id查询行为实体
        if (!ObjectUtils.isEmpty(userId)) {
            return getOne(Wrappers.<ApBehaviorEntry>lambdaQuery().eq(ApBehaviorEntry::getEntryId, userId).eq(ApBehaviorEntry::getType, 1));
        }else if (!ObjectUtils.isEmpty(equipmentId) && equipmentId != 0) {
            return getOne(Wrappers.<ApBehaviorEntry>lambdaQuery().eq(ApBehaviorEntry::getEntryId, equipmentId).eq(ApBehaviorEntry::getType, 0));
        }
        return null;
    }
}
